<?php

/*
 *  Action    $2
 * 
 *  Reveal your hand.
 *  +1 Card per Victory card revealed.
 *  If this is the first time you played a Crossroads this turn, +3 Actions.
 * 
 */

class Crossroads extends Card implements iAction, iKingdom, iHinterlands {

    public function __construct() {
        parent::__construct("Crossroads", 2);
    }

    public function getDescription() {
        return array(
            "Reveal your hand.",
            "+1 Card per Victory card revealed",
            "If this is the first time you played a Crossroads this turn, +3 Actions.");
    }

    public function getDisplayName($quantity = 1) {
        if ($quantity == 1) {
            return "Crossroads";
        }
        return $quantity . " Crossroads";
    }

    public function play(Game $game) {

        // reveal hand
        $playHand = $game->getPlayHand();
        ScreenDisplay::addScreenMessage($game, true, "reveal " . nicePrint($playHand), "reveals " . ScreenDisplay::$LMSG);

        // +1 card per Victory card revealed
        $victoryCount = 0;
        foreach ($playHand as $card) {
            if ($card instanceof iVictory) {
                $victoryCount += 1;
            }
        }
        $drawed_cards = $game->drawCards($victoryCount);
        ScreenDisplay::addScreenMessage($game, true, "draw " . nicePrint($drawed_cards), "draws " . sizeof($drawed_cards) . " cards");

        // is it the first time?
        $playedCards = $game->getPlayedCards();
        $firstTime = true;
        $crossroadsKey = $this->getKey();
        foreach ($playedCards as $card) {
            if ($card->getKey() == $crossroadsKey) {
                $firstTime = false;
                break;
            }
        }
        if ($firstTime) {
            $game->addActions(3);
            ScreenDisplay::addScreenMessage($game, false, " and get +3 actions", " and gets +3 actions");
        }

        $game->cardActionFinished();
        return true;
    }

}

?>